<include file="Public:header" />
<script type="text/javascript" charset="UTF-8" src="__PUBLIC__/Partner/js/my97date/wdatepicker.js"></script>
<div class="headbar">
    <div class="position"><span>商品</span><span>></span><span>商品管理</span><span>></span><span>商品列表</span></div>
    <div class="operating">
        <a href="{:U('Goods/goods_edit')}"><button class="operating_btn" type="button" ><span class="addition">添加商品</span></button></a>
        <a href="javascript:void(0);"><button class="operating_btn" type="button" onclick="selectAll('id[]')"><span class="sel_all">全选</span></button></a>
        <a href="javascript:void(0);"><button class="operating_btn" type="button" onclick="goods_del()"><span class="delete">删除</span></button></a>
        <a href="{:U('Goods/goods_recycle_list')}"><button class="operating_btn" type="button" ><span class="recycle">回收站</span></button></a>
    </div>

    <div class="searchbar" id="adv_searchbar">
        <form action="" method="get" name="searchListForm">
            <select class="auto" name="search[brand_id]" id="brand_id">
                <option value="">选择商品品牌</option>
                <foreach name='brand' item='item'>
                    <option value="{$item.id}">{$item.name}</option>
                </foreach>
            </select>
            <select class="auto" name="search[name]">
                <option value="go.name">商品名</option>
                <option value="seller.true_name">商户真实名称</option>
            </select>
            <input class="small" name="search[keywords]" type="text" value="" />

            <!--分类数据显示-->
            <span id="__categoryBox" style="margin-bottom:8px"></span>
            <button class="btn" type="button" name="_goodsCategoryButton"><span class="add">分类</span></button>
            <include file="Public:set_Category" name="search[category_id]"/>

            <button class="btn" type="submit"  onclick='changeAction(false)'><span class="sel">筛 选</span></button>
            <button class="btn" onclick='changeAction(true)'><span class="sel">导出Excel</span></button>
        </form>
    </div>
</div>

<div class="wxeditor">
	<div id="previewbox" style="display:none;">
		<div style="height:85%; overflow-y: scroll; padding-right: 5px;">
			<div style="font-size: 18px; line-height: 24px; font-weight: 700">{$info.title}</div>
			<div>
				<em style="color: #8c8c8c; font-style: normal; font-size: 12px;">{$info.create_time}</em>
				<a style="font-size: 12px; color: #607fa6"
					href="javascript:void(0);" id="post-user"></a>
			</div>
			<div id="preview" class="preview"></div>
		</div>

		<div
			style="position: absolute; right: 50px; top: 40px; cursor: pointer; width: 50px; height: 50px; font-size: 50px; font-weight: 700"
			id="phoneclose">X</div>
	</div>
</div>

<form action="" method="post" name="orderForm">
    <div class="content">
        <table class="list_table">
            <colgroup>
                <col width="40px" />
                <col width="260px" />
                <col width="90px" />
                <col width="90px" />
                <col width="90px" />
                <col width="90px" />
                <col width="70px" />
                <col width="70px" />
                <col width="110px" />
            </colgroup>

            <thead>
                <tr>
                    <th>选择</th>
                    <th>商品名称</th>
                    <th>品牌</th>
                    <th>分类</th>
                    <th>销售价</th>
                    <th>市场价</th>
                    <th>二维码数量</th>
                    <th>排序</th>
                    <th>操作</th>
                </tr>
            </thead>

            <tbody>
            <foreach name='goods' item='item'>
                <tr>
                    <td><input name="id[]" type="checkbox" value="{$item.id}" /></td>
                    <td><img src="__ROOT__/{$item.img}" class='ico' width="100"/><a class="orange" href="javascript:void(0);" onclick="xiang('{$item.id}')" title="{$item.name}">{$item.name}</a></td>
                    <td>{$item.brand_name}</td>
                    <td>{$item.category}</td>
                    <td>{$item.sell_price}</td>
                    <td>{$item.market_price}</td>
                    <td>{$item.code.counts}（{$item.code.1}/<span class="red">{$item.code.2}</span>）</td>
                    <td><input type="text" class="tiny" value="{$item['sort']}" onchange="changeSort({$item.id},this);" /></td>
                    <td>
                        <a href="{:U('Goods/goods_edit',array('id'=> $item[id]))}" title="编辑"><img class="operator" src="__PUBLIC__/Partner/images/admin/icon_edit.gif" alt="编辑" /></a>
                        <a href="javascript:void(0)" onclick="delModel({link:'{:U('Goods/goods_del',array('id'=> $item[id]))}'})" title="删除"><img class="operator" src="__PUBLIC__/Partner/images/admin/icon_del.gif" alt="删除" /></a>
                        <a href="javascript:void(0);" title="预览" onclick="xiang('{$item.id}')" title="预览"><img src="__PUBLIC__/Partner/images/admin/seller_ico.png" alt="预览"/></a>
                    </td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </div>
</form>

{$page}

<script type="text/javascript">
//商品详情
function xiang(idd){
	if ($("#previewbox").css("display") == "block") {
		$("#previewbox").hide()
	} else {
		$("#previewbox").show()
	}
	var add = document.getElementById('preview');
    $.ajax({
        type: "POST",
        url: "{:U('Goods/home1')}",
        data:{id:idd},
        dataType: "json",
        success: function(e){
        	if(e.status==1){	
        		add.innerHTML = e.data;
        	}	
        },
        error: function(){
        }
    });	
}
    //DOM加载
    $(function(){
    	$("#phoneclose").on('click', function() {
			$("#previewbox").hide()
		}); 
        var searchData = {$search};
        if(searchData){
        for(var index in searchData)
        {
            $('[name="search['+index+']"]').val(searchData[index]);
        }
        }
        $("#brand_id").blur(function(){
            var brand_id = $(this).val();
            $('input[name="search[brand_id]"]').val(brand_id);
        });
    });
    //修改排序
    function changeSort(gid,obj)
    {
        var selectedValue = obj.value;
        $.getJSON("{:U('Goods/ajax_sort')}",{"id":gid,"sort":selectedValue});
    }

    //upload csv file callback
    function artDialogCallback(message)
    {
        message ? alert(message) : window.location.reload();
    }

    //删除
    function goods_del()
    {
        var flag = 0;
        $('input:checkbox[name="id[]"]:checked').each(function(i){flag = 1;});
        if(flag == 0)
        {
            alert('请选择要删除的数据');
            return false;
        }
        $("form[name='orderForm']").attr('action',"{:U('Goods/goods_del')}");
        confirm('确定要删除所选中的信息吗？','formSubmit(\'orderForm\')');
    }
    //商品导出或查询切换
    function changeAction(excel)
    {
        //setCreatetimeVal();
        if(excel)
        {
            $("form[name=\"searchListForm\"]").attr("action", "{:U('Goods/goods_export')}");
            $("form[name=\"searchListForm\"]").attr("target", "_blank");
        }
        else
        {
            $("form[name=\"searchListForm\"]").attr("action", "{:U('Goods/goods_list')}");
            $("form[name=\"searchListForm\"]").attr("target", "_self");
        }
    }
</script>
<include file="Public:footer" />